package com.chenxin.wms.controller;

import com.chenxin.common.annotation.Log;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.core.page.TableDataInfo;
import com.chenxin.common.enums.BusinessType;
import com.chenxin.common.utils.poi.ExcelUtil;
import com.chenxin.system.domain.InterfaceLog;
import com.chenxin.system.service.IInterfaceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 接口日志Controller
 *
 * @author gry
 * @date 2025-04-21
 */
@RestController
@RequestMapping("/wms/apiLog")
public class ApiLogController extends BaseController {
    @Autowired
    private IInterfaceLogService apiLogService;

    /**
     * 查询接口日志列表
     */
    @PreAuthorize("@ss.hasPermi('wms:apiLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(InterfaceLog apiLog) {
        startPage();
        List<InterfaceLog> list = apiLogService.selectApiLogList(apiLog);
        return getDataTable(list);
    }

    /**
     * 导出接口日志列表
     */
    @PreAuthorize("@ss.hasPermi('wms:apiLog:export')")
    @Log(title = "接口日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InterfaceLog apiLog) {
        List<InterfaceLog> list = apiLogService.selectApiLogList(apiLog);
        ExcelUtil<InterfaceLog> util = new ExcelUtil<>(InterfaceLog.class);
        util.exportExcel(response, list, "接口日志数据");
    }

    /**
     * 获取接口日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:apiLog:query')")
    @GetMapping(value = {"/", "/{apiId}"})
    public AjaxResult getInfo(@PathVariable(value = "apiId", required = false) Long apiId) {
        return success(apiLogService.selectApiLogByApiId(apiId));
    }

    /**
     * 新增接口日志
     */
    @PreAuthorize("@ss.hasPermi('wms:apiLog:add')")
    @Log(title = "接口日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InterfaceLog apiLog) {
        return toAjax(apiLogService.insertApiLog(apiLog));
    }
}
